package com.aya.export.aspect;

import com.aya.export.annotation.ExcelExport;
import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.aop.Pointcut;
import org.springframework.aop.PointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ExportAspect implements PointcutAdvisor {  // 实现Advisor接口‌:ml-citation{ref="1,2" data="citationList"}

    // 注入业务服务（如Excel导出逻辑）
    @Autowired
    private ExcelExportService excelExportService;

    // 定义切点（匹配@Export注解的方法）‌:ml-citation{ref="1,2" data="citationList"}
    @Override
    public Pointcut getPointcut() {
        return new AnnotationMatchingPointcut(null, ExcelExport.class);  // 类/方法级别注解匹配
    }

    // 定义通知（环绕逻辑）‌:ml-citation{ref="1,2" data="citationList"}
    @Override
    public Advice getAdvice() {
        return (MethodInterceptor) invocation -> excelExportService.processExport(invocation);
    }

    @Override
    public boolean isPerInstance() {
        return false;  // 默认单例模式
    }
}